//package com.lee.recyclerview524lx.fragment;
//
//
//import android.content.Context;
//import android.content.Intent;
//import android.content.SharedPreferences;
//import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.support.v4.app.Fragment;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.Toast;
//
//import com.lee.recyclerview524lx.R;
//import com.lee.recyclerview524lx.adapter.ArticleAdapter;
//import com.lee.recyclerview524lx.bean.ArticleBean;
//import com.lee.recyclerview524lx.model.ArticleModel;
//
//import java.util.List;
//
//import static android.content.Context.MODE_PRIVATE;
//
///**
// * Created by Neusoft on 2017/4/9.
// */
//
//public class Fragment1_Article extends Fragment implements ArticleListener{
//     private View view=null;
//    private Context context;
//    RecyclerView recyclerView;
//    List<ArticleBean> list;
//    ArticleAdapter articleAdapter;
//    RecyclerView.LayoutManager layoutManager;
//    SharedPreferences preferences;
//    final static String PREF_NAME="loginPref";
//    String sessionId;
//    private int lastVisibleItemPosition;
//    private static int cur_page=1;
//    @Nullable
//    @Override
//    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        context=getActivity();
//       //动态加载Fragment1的布局文件
//        view=inflater.inflate(R.layout.fragment1,container,false);
//        initRecyclerView();
//
//        ArticleModel articleModel=new ArticleModel();
//        sessionId=readSessionIdfromPref();
//        articleModel.getResultList("article",cur_page,sessionId,this);//请求网络访问
//        //返回动态生成的view
//        return view;
//    }
//
//    void initRecyclerView(){
//        recyclerView=(RecyclerView)view.findViewById(R.id.recyclerView);
//        layoutManager=new LinearLayoutManager(context);
//        recyclerView.setLayoutManager(layoutManager);
//
//        articleAdapter=new ArticleAdapter(context,list);
//        ArticleAdapter.OnItemClickListener onItemClickListener= new ArticleAdapter.OnItemClickListener() {
//            @Override
//            public void onItemClick(View view, int position) {
//                Intent intent=new Intent(getActivity(), ViewArticleActivity.class);
//                intent.putExtra("resid",list.get(position).getId());
//                startActivity(intent);
//            }
//        };
//
//        articleAdapter.setOnItemClickListener(onItemClickListener);
//
//        recyclerView.setAdapter(articleAdapter);
//
//
//        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
//            @Override
//            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
//                super.onScrollStateChanged(recyclerView, newState);
//                if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItemPosition + 1 == list.size()) {
//                    cur_page+=1;
//                    ////AmicoolFactory.getInstance(mod).getResultList(mod,cur_page,SessionID,listener);
//                    new ArticleModel().getResultList("article",cur_page,sessionId,Fragment1_Article.this);
//                }
//            }
//
//            @Override
//            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
//                super.onScrolled(recyclerView, dx, dy);
//                //lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
//                lastVisibleItemPosition=list.size()-1;
//            }
//        });
//    }
//
//
//    @Override
//    public void onResponse(List<ArticleBean> beanList) {      //ArticleListener
////        list=beanList;
////        articleAdapter.setList(list);//把最新的list数据传递到adpter里，更新显示
//        if (cur_page==1){//curpage==1的时候，说明还没有加载过数据
//            this.list=beanList;
//            articleAdapter.setList(list);
//        }else{
//            list.removeAll(beanList);
//            list.addAll(0,beanList);
//            articleAdapter.setList(list);
//        }
//
//    }
//
//    @Override
//    public void onFail(String msg) {    //ArticleListener
//        Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
//    }
//
//    public String readSessionIdfromPref(){
//        preferences=context.getSharedPreferences(PREF_NAME,MODE_PRIVATE );
//        String sessionId=preferences.getString("sessionId","");
//        return sessionId;
//    }
//}
